版权声明:本文为博主原创文章,转载请注明出处:http://blog.jerkybible.com/2013/09/12/2013-09-12-CODE 7 Word Ladder/
访问原文「CODE 7. Word Ladder」
Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:
- Only one letter can be changed at a time
- Each intermediate word must exist in the dictionary
For example,
Given:
start="hit"
end="cog"
dict=["hot","dot","dog","lot","log"]
As one shortest transformation is"hit" -> "hot" -> "dot" -> "dog" -> "cog"
,
return its length5
.
Note:
- Return 0 if there is no such transformation sequence.
- All words have the same length.
- All words contain only lowercase alphabetic characters.
|
|
Konw Something:
- StringBuilder has a method named setCharAt(int arg0,char arg1).